package com.ypan.creator;

/**
 * @Author ypan
 * @Date on 2021/3/8  16:57
 * @Desc 普通工厂模式
 * 这个其实和简单工厂模式差不太多，就是将工厂继续拆分，
 * 比如说刚刚EasyBallFactory是一个总工厂，
 * 我们现在拆分成SoccerFactory和BasketBallFactory分别生产足球和篮球。
 * 某个工厂内部可以根据需求生产不同的产品，比如说soccer可以生产不同大小的出来。
 */
public class CommonBallFactory {

    interface BallFactory{
        Ball createBall();
    }

    static class Ball{

        private String name;

        private Integer pnum;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Integer getPnum() {
            return pnum;
        }

        public void setPnum(Integer pnum) {
            this.pnum = pnum;
        }

        @Override
        public String toString() {
            return "Ball{" +
                    "name='" + name + '\'' +
                    ", pnum=" + pnum +
                    '}';
        }
    }

    static class BasketBallFactory implements BallFactory{

        public Ball createBall() {
            Ball ball = new Ball();
            ball.setName("BasketBall");
            ball.setPnum(10);
            return ball;
        }
    }

    static class FootBallFactory implements BallFactory{
        public Ball createBall() {
            Ball ball = new Ball();
            ball.setName("FootBall");
            ball.setPnum(12);
            return ball;
        }
    }

    public static void main(String[] args) {
        BallFactory ballFactory = new FootBallFactory();
        System.out.println(ballFactory.createBall());
    }
}
